$("document").ready(function() {
	//alert('demand_pair ajax');
	
	//partition_the
	//分區使用
	$( "#partition_the222" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 
		//alert('111');
	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/partition_the",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });
	
	
	
	//客戶來源
	$( "#customer_source" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/customer_source",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });
	
	
	//管理
	$( "#management" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/management",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });
	
	//附屬配備
	$( "#accessories_with" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/accessories_with",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });
	  
	  	
	
	//公共設施
	$( "#public_facilities" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/public_facilities",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });
	
	
	//物件型式
	$( "#object_styles" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/object_stype",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });


	//落地窗座向
	$( "#windows" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/windows_json",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });




	$( "#facing_the_household" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/windows_json",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });



	  $( "#building_facing" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/ajax_basedata/windows_json",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });




	//市調狀態
	$( "#object_usage" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/object_usage/object_usage_josn",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });	


});